<template>
  <div class="goods-relevant">
    <div class="header">
      <i class="icon" />
      <span class="title">{{goodsId?'同类商品推荐':'猜你喜欢'}}</span>
    </div>
    <!-- 此处使用改造后的slideshow.vue -->
    <Slideshow :slides="slides" :autoPlay="true"></Slideshow>
  </div>
</template>

<script>
import { findRelevantGoods } from '../../../api/product'
import { ref } from 'vue'
export default {
  // 同类推荐，猜你喜欢
  name: 'GoodsRelevant',
  props: {
    goodsId: {
      type: String,
      default: ''
    }
  },
  setup (props) {
    // console.log(props.goodsId)
    // 获取sliders提供给轮播图使用 sliders= [[], [], [], []]
    const slides = ref([])
    findRelevantGoods({ id: props.goodsId }).then(data => {
      // sliders.value.push(data.result.map(item => item.name))
      // console.log(data.result)
      const pageSize = 4
      const pageCount = Math.ceil(data.result.length / 4)
      for (let index = 0; index < pageCount; index++) {
        slides.value.push(data.result.slice(pageSize * index, pageSize * (index + 1)))
      }
      // console.log(slides.value)
    })
    return { slides }
  }
}
</script>

<style scoped lang='less'>
@import '../../../assets/styles/variable.less';
.goods-relevant {
  background: #fff;
  min-height: 460px;
  margin-top: 20px;
  .header {
    height: 80px;
    line-height: 80px;
    padding: 0 20px;
    .title {
      font-size: 20px;
      padding-left: 10px;
    }
    .icon {
      width: 16px;
      height: 16px;
      display: inline-block;
      border-top: 4px solid @c;
      border-right: 4px solid @c;
      box-sizing: border-box;
      position: relative;
      transform: rotate(45deg);
      &::before {
        content: "";
        width: 10px;
        height: 10px;
        position: absolute;
        left: 0;
        top: 2px;
        background: lighten(@c, 40%);
      }
    }
  }
}
:deep(.slideshow) {
  height: 360px;
  // .carousel {
    .slideshow-indicator {
      bottom: 30px;
      span {
        &.active {
          background: @c;
        }
      }
    }
    .slideshow-btn {
      top: 110px;
      opacity: 1;
      background: rgba(0,0,0,0.2);
      color: #ddd;
      i {
        font-size: 30px;
      }
    }
  // }
}
</style>
